package com.fzhucc.modules.thinktank.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.Hibernate;
import org.hibernate.annotations.Comment;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

/**
 * 产业资本
 *
 * @author Woolsen
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "tt_capital")
public class Capital {

    /**
     * 智库类型 - 产业资本
     */
    public static final String THINKTANK_TYPE_CAPITAL = "产业资本";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Comment("ID")
    private Long id;

    @Comment("图片链接")
    private String photo;

    @Comment("名称")
    private String name;

    @ElementCollection
    @JoinTable(name = "tt_capital_tags")
    private List<String> tags;

    @Comment("描述")
    private String description;

    @Comment("是否展示")
    private Boolean isShow;

    @Comment("用户id")
    private Long userId;

    @Comment("专家类型")
    private String type;

    @Comment("是否假删除")
    private Boolean isDelete;

    @Comment("排序")
    private Integer sort;

    @Comment("区域划分")
    public String orgArea;

    public void copy(Capital source) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        Capital capital = (Capital) o;
        return id != null && Objects.equals(id, capital.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
